set more off
cap log close
log using log/data_analysis, replace



********************************************************************************
* Controls and outcomes set.
global Controles0
global Controles1 Mujer edad Educ1 Educ2 Educ3 JefeHogar Working saldo_uf rem_actual
global OutcomesADM Afiliado cambio_fondo cambio_afp clave_activa
global Controles_alt $Descriptive ContributedVol cot_vol Contributed cot_obli saldo_uf monto_ahorrado $Priors $Knowledge

********************************************************************************
* Variables list:
global Descriptive Mujer edad Educ1 Educ2 Educ3 Educ4 JefeHogar Working LaborForce rem_actual Afiliado
global Savings NCotVol NCot ContVolPrevio TotCotVol TotCot saldo_uf monto_ahorrado //meses_cot_actual bono_uf
global Priors deseada_pens esperada_pens res_sim_1 ErrorPension ErrorPensionRel AFP_Importante
global Knowledge comodidad_dec_financieras CalculoPension PctajeAFP FinancKnow
global Heterogeneidad ErrorPension esperada_pens rem_actual indep_pre FinancKnow CalculoPension PctajeAFP RepRate Pensionable ContVolPrevio //edad


global LineaBase $Descriptive $Savings $Priors $Knowledge
global LineaBase1 Mujer edad Educ1 Educ2 Educ3 JefeHogar Working LaborForce rem_actual ContVolPrevio saldo_uf monto_ahorrado deseada_pens esperada_pens ErrorPensionRel AFP_Importante $Knowledge



********************************************************************************
* Table 1: Balance
********************************************************************************
use "data/Base_ADM_TotalFinal", clear

keep if post==0

replace rem_actual = rem_actual /1000
replace res_sim_1 = res_sim_1/1000
replace ErrorPension = ErrorPension/1000
replace deseada_pens = deseada_pens/1000
replace esperada_pens =esperada_pens/1000

label var Afiliado "Affiliated"
label var rem_actual "Wage (avg. M\char36 last 6 months)"
label var res_sim_1 "Estimated pension (M\char36)"
label var deseada_pens "Desired pension (M\char36)"
label var esperada_pens "Expected pension (M\char36)"
label var ErrorPension "Expected Pension Mistake (M\char36)"
label var ErrorPensionRel "Expected Pension Mistake"

foreach var of varlist $LineaBase {

	sum `var' if Tratamiento ~= .
	local N_`var': di %12.0fc r(N)

	* Mean:
	forvalues i = 0/1 {
		sum `var' if Tratamiento == `i'
			local n`i'_`var': di %12.0g r(N)
		local m`i'_`var' :di %12.3fc r(mean)
	}

	* Difference:
	areg `var' Tratamiento, a(periodo_exp) robust
		test Tratamiento == 0
			local st_`var'=cond(r(p)<.01,"***",cond(r(p)<.05,"**",cond(r(p)<.1,"*","")))
			local p_`var': di %12.3fc r(p)
		local b_`var': di %12.3fc _b[Tratamiento]
		local se_`var': di %12.3fc _se[Tratamiento]
}


{
texdoc init tab/balance.tex, replace force
tex \begin{table}[!ht]
tex \centering
tex \caption{Balance}
tex \label{tab:balance}
tex \resizebox{0.45\textheight}{!}{
tex \begin{tabular}{lcccc} \hline
tex                           &           & \multicolumn{2}{c}{Mean} & Difference \\ \cline{3-4}
tex                           &     N     &  Control   & Treatment   & T-C        \\ \hline
tex {\it Descriptive:} \\
foreach var of varlist $Descriptive {
tex \quad `: var label `var'' & `N_`var'' & `m0_`var'' & `m1_`var''  & `b_`var''`st_`var'' \\
tex                           &           &            &             & (`se_`var'')        \\
}
tex {\it Savings:} \\
foreach var of varlist $Savings {
tex \quad `: var label `var'' & `N_`var'' & `m0_`var'' & `m1_`var''  & `b_`var''`st_`var'' \\
tex                           &           &            &             & (`se_`var'')        \\
}
tex {\it Priors:}\\
foreach var of varlist $Priors {
tex \quad `: var label `var'' & `N_`var'' & `m0_`var'' & `m1_`var'' & `b_`var''`st_`var''\\
tex                           &           &            &            & (`se_`var'')\\
}
tex {\it Knowledge:} \\
foreach var of varlist $Knowledge {
tex \quad `: var label `var'' & `N_`var'' & `m0_`var'' & `m1_`var''  & `b_`var''`st_`var'' \\
tex                           &           &            &             & (`se_`var'')        \\
}
tex \hline
tex \multicolumn{5}{c}{Robust standard errors in parenthesis.} \\
tex \multicolumn{5}{c}{*** p$<$0.01, **p$<$0.05, *p$<$0.1}
tex \end{tabular}}
tex \end{table}
texdoc close
}


********************************************************************************
* Table A.1: For participants
********************************************************************************

use "data/Base_ADM_TotalFinal", clear

keep if post==0

sum Mujer
sum edad, d

gen nocotvol=NCotVol==0
sum nocotvol

sum NCotVol if nocotvol~=1

sum rem_actual, d



*TABLE A.2: ATTRITION

use "data/Encuesta_SEG_Preparada", clear

replace rem_actual = rem_actual /1000
replace res_sim_1 = res_sim_1/1000
replace ErrorPension = ErrorPension/1000
replace deseada_pens = deseada_pens/1000
replace esperada_pens =esperada_pens/1000

label var AFP_Importante "AFP important for ret."
label var rem_actual "Wage (avg. (M\char36) 6 months)"
label var res_sim_1 "Estimated pension (M\char36)"
label var deseada_pens "Desired pension (M\char36)"
label var esperada_pens "Expected pension (M\char36)"
label var ErrorPension "Mistake (M\char36) in exp. pen."
label var CalculoPension "Knows how pens. are calc."
label var saldo_uf "Balance mand. acc. (UF)"
label var FinancKnow "Fin. know. score (1-3)"


gen Seg_T = Seguimiento*Tratamiento

foreach var of varlist $LineaBase {

	sum `var' if Seguimiento == 0 & Tratamiento == 0
	local N0C_`var': di %12.0fc r(N)
	local M0C_`var': di %12.3fc r(mean)

	sum `var' if Seguimiento == 0 & Tratamiento == 1
	local N0T_`var': di %12.0fc r(N)
	local M0T_`var': di %12.3fc r(mean)

	sum `var' if Seguimiento == 1 & Tratamiento == 0
	local N1C_`var': di %12.0fc r(N)
	local M1C_`var': di %12.3fc r(mean)

	sum `var' if Seguimiento == 1 & Tratamiento == 1
	local N1T_`var': di %12.0fc r(N)
	local M1T_`var': di %12.3fc r(mean)

	* Difference:
	areg `var' Seguimiento if Tratamiento == 0, a(periodo_exp) robust
		test Seguimiento == 0
			local st1_`var'=cond(r(p)<.01,"***",cond(r(p)<.05,"**",cond(r(p)<.1,"*","")))
			local p1_`var': di %12.3fc r(p)
			local b1_`var': di %12.3fc _b[Seguimiento]
			local se1_`var': di %12.3fc _se[Seguimiento]
	areg `var' Seguimiento if Tratamiento == 1, a(periodo_exp) robust
		test Seguimiento == 0
			local st2_`var'=cond(r(p)<.01,"***",cond(r(p)<.05,"**",cond(r(p)<.1,"*","")))
			local p2_`var': di %12.3fc r(p)
			local b2_`var': di %12.3fc _b[Seguimiento]
			local se2_`var': di %12.3fc _se[Seguimiento]
	areg `var' Tratamiento Seguimiento Seg_T, a(periodo_exp) robust
		test Seg_T == 0
			local st3_`var'=cond(r(p)<.01,"***",cond(r(p)<.05,"**",cond(r(p)<.1,"*","")))
			local p3_`var': di %12.3fc r(p)
			local b3_`var': di %12.3fc _b[Seg_T]
			local se3_`var': di %12.3fc _se[Seg_T]
}

{
texdoc init tab/table_attrition.tex, replace force

tex \begin{table}[!ht]
tex \centering
tex \caption{Attrition}
tex \label{tab:attrition}
tex \resizebox{1\textwidth}{!}{
tex \begin{tabular}{lcccccccccccccc} \toprule
tex 					      & \multicolumn{5}{c}{General Info}                                               &&  \multicolumn{5}{c}{Personalized Info}                            &&                             \\ \cline{2-6} \cline{8-12}
tex                           & \multicolumn{2}{c}{(1)}                          && \multicolumn{2}{c}{(2)}                       && \multicolumn{2}{c}{(3)}                        && \multicolumn{2}{c}{(4)}     \\
tex                           & \multicolumn{2}{c}{No Follow-Up} && \multicolumn{2}{c}{Follow-Up}              && \multicolumn{2}{c}{No Follow-Up} && \multicolumn{2}{c}{Follow-Up} & Diff.    & Diff.    & Double \\
tex                           &       N      &       Mean                        &&      N       &      Mean   &&      N       &    Mean           &&     N      &      Mean        & (2)- (1) & (4)- (3) & Diff.  \\
tex \midrule
tex {\it Descriptive:} \\
foreach var of varlist $Descriptive {
tex `: var label `var'' &  `N0C_`var'' &    `M0C_`var''                    && `N1C_`var''   & `M1C_`var''                   &&  `N0T_`var'' &    `M0T_`var''                  && `N1T_`var''   & `M1T_`var''                 & `b1_`var''`st1_`var''& `b2_`var''`st2_`var'' & `b3_`var''`st3_`var'' \\
tex                           &              &                                   &&               &                               &&              &                                 &&               &                             & (`se1_`var'')        & (`se2_`var'')         & (`se3_`var'')         \\
}
tex {\it Savings:} \\
foreach var of varlist $Savings {
tex `: var label `var'' &  `N0C_`var'' &    `M0C_`var''                    && `N1C_`var''   & `M1C_`var''                   &&  `N0T_`var'' &    `M0T_`var''                  && `N1T_`var''   & `M1T_`var''                 & `b1_`var''`st1_`var''& `b2_`var''`st2_`var'' & `b3_`var''`st3_`var'' \\
tex                           &              &                                   &&               &                               &&              &                                 &&               &                             & (`se1_`var'')        & (`se2_`var'')         & (`se3_`var'')         \\
}
tex {\it Priors:} \\
foreach var of varlist $Priors {
tex `: var label `var'' &  `N0C_`var'' &    `M0C_`var''                    && `N1C_`var''   & `M1C_`var''                   &&  `N0T_`var'' &    `M0T_`var''                  && `N1T_`var''   & `M1T_`var''                 & `b1_`var''`st1_`var''& `b2_`var''`st2_`var'' & `b3_`var''`st3_`var'' \\
tex                           &              &                                   &&               &                               &&              &                                 &&               &                             & (`se1_`var'')        & (`se2_`var'')         & (`se3_`var'')         \\
}
tex {\it Knowledge:} \\
foreach var of varlist $Knowledge {
tex `: var label `var'' &  `N0C_`var'' &    `M0C_`var''                    && `N1C_`var''   & `M1C_`var''                   &&  `N0T_`var'' &    `M0T_`var''                  && `N1T_`var''   & `M1T_`var''                 & `b1_`var''`st1_`var''& `b2_`var''`st2_`var'' & `b3_`var''`st3_`var'' \\
tex                           &              &                                   &&               &                               &&              &                                 &&               &                             & (`se1_`var'')        & (`se2_`var'')         & (`se3_`var'')         \\
}
tex \bottomrule
tex \multicolumn{15}{c}{Robust standard errors in parenthesis.} \\
tex \multicolumn{15}{c}{*** p$<$0.01, **p$<$0.05, *p$<$0.1}
tex \end{tabular}}
tex \end{table}
texdoc close
}

*FIGURE 3***

use "data/Base_Encuesta_procesada", clear

label variable deseada_pens "Desired pension ($)"
label variable esperada_pens "Expected pension ($)"
label var ErrorPension "Mistake in expected pension (CL$)"
label var ErrorPensionABS "Mistake (absolute value) ($)"
label var rem_actual "Wage (avg. $ last 6 months)"

replace ErrorPensionRel = (res_sim_1-esperada_pens)/(res_sim_1+esperada_pens) // Relative pension error
label var ErrorPensionRel	"(Simulated Pension-Expected Pension)/(Simulated Pension + Expected Pension)"

hist ErrorPensionRel                         , kdensity kdenopts(lcolor(gs8)) fcolor(white) lcolor(black) percent title("Mistake in Expected Pension") name(ErrorPensionRel1, replace)
graph export "fig/figure_mistake.png", replace


********************************************************************************
* Figure A.4: Graph was generated from the following data
********************************************************************************

use "data/Base_ADM_TotalFinal", clear

keep if post==1

tab NCotVol if Tratamiento==1
tab NCotVol if Tratamiento==0




*FIGURE 4

use "data/Base_ADM_preparada_Long.dta", clear

  merge m:1 ID1 ID2 using "src/sim_v2.dta"
  keep if _merge==3
  drop _merge

xtset ID1 Months
gen treat = Tratamiento
gen month = date_dev - periodo_exp
keep if month==-1

gen premio_dens	=	(sv2_pension_dens-sv2_pension)/sv2_pension
gen premio_apv	=	(sv2_pension_apv-sv2_pension)/sv2_pension
gen premio_jub	=	(sv2_pension_jub-sv2_pension)/sv2_pension

replace premio_dens=0.3 if premio_dens>0.3 & premio_dens~=.

hist premio_dens, width(0.01) xline(0.16, lpattern(dash) lwidth(thick) lcolor(gs7)) fcolor(none) lcolor(black) xlabel(0(0.1)0.3) xscale(range(0 0.1 0.2 0.3)) xtitle("Return to increasing density")
graph export "fig/dens.pdf", replace

hist premio_apv, width(0.01) xline(0.1, lpattern(dash) lwidth(thick) lcolor(gs7)) fcolor(none) lcolor(black) xlabel(0(0.1)0.3) xscale(range(0 0.1 0.2 0.3)) xtitle("Return to voluntary savings")
graph export "fig/apv.pdf", replace

hist premio_jub, width(0.01) xline(0.08, lpattern(dash) lwidth(thick) lcolor(gs7)) fcolor(none) lcolor(black) xlabel(0(0.1)0.3) xscale(range(0 0.1 0.2 0.3)) xtitle("Return to delaying retirement")
graph export "fig/jub.pdf", replace


*FIGURES 5 and 6***

use "data/Base_ADM_preparada_Long", clear

gen var1 = ContributedVol
gen var2 = ihs_cot_vol
gen var3 = Contributed
gen var4 = ihs_cot_obli
gen var5 = pensionado
gen var6 = ihs_savings
gen treat = (Tratamiento == 1)
gen month = date_dev - periodo_exp

estimates clear



sort ID1 month
xtset ID1 month

foreach var of varlist $Controles1 {
	gen `var'_miss = (`var'==.)
	replace `var' = 0 if `var'==.
	tab month `var'_miss
	* global Controles1 $Controles1 `var'_miss
}

* Regression months. Each of these regressions should have N=2547
forvalues k=1/6{
forvalues i = 1/11 {

	* outcome mean for control group, months 1 to 6 post treatment
	estpost summarize var`k' if Tratamiento == 0 & month == `i'
	if abs(el(e(mean),1,1))>100{
		local mean_var`k'_`i': di %12.0fc el(e(mean),1,1)
		}
	else{
		local mean_var`k'_`i': di %12.3fc el(e(mean),1,1)
		}
		local mean_var`k'_`i' = 0

	* regression
	areg var`k' Tratamiento L12.(var`k' $Controles1) if month == `i', a(periodo_exp) robust
	local N_var`k': di %12.0fc e(N)

	foreach x in Tratamiento {
		test `x'
		local s_var`k'_`i'=cond(r(p)<.01,"***",cond(r(p)<.05,"**",cond(r(p)<.1,"*","")))
		if abs(_b[`x'])>100{
			local b_var`k'_`i': di %12.0fc _b[`x']
			}
		else{
			local b_var`k'_`i': di %12.3fc _b[`x']
			}
		if abs(_se[`x'])>100{
			local se_var`k'_`i': di %12.0fc _se[`x']
			}
		else{
			local se_var`k'_`i': di %12.3fc _se[`x']
			}
	}
}
}
* Make matrix for graph
matrix control		   = J(11,1,.)
matrix estimates_mid = J(11,1,.)
matrix estimates_upp = J(11,1,.)
matrix estimates_low = J(11,1,.)
forvalues k= 1/6{
forvalues j = 1/11 {
matrix estimates_mid[`j',1] = `b_var`k'_`j''
  matrix estimates_upp[`j',1] = `b_var`k'_`j'' +  1.645*`se_var`k'_`j''
  matrix estimates_low[`j',1] = `b_var`k'_`j'' -  1.645*`se_var`k'_`j''
}
* Generate graph date
clear
svmat double control, name(control)
rename control1 control
svmat double estimates_mid, name(estimates_mid)
rename estimates_mid1 estimates_mid
svmat double estimates_upp, name(estimates_upp)
rename estimates_upp1 estimates_upp
svmat double estimates_low, name(estimates_low)
rename estimates_low1 estimates_low
* graph
gen month = _n
if `k'==1|`k'==3|`k'==5{
twoway  (line    estimates_mid                 month    , lcolor(gs3) ) ///
				(scatter estimates_mid                 month    , mcolor(gs3) ) ///
				(rcap    estimates_low estimates_upp   month    , lcolor(gs3) ) ///
				, ylabel(-.05(.01).05) ///
				xlabel(1(1)11) xtitle("month") yline(0) ///
				legend(order(2 "Treatment coef." 5 "90% confidence interval") ring(0) ) ///
				graphregion(color(white))
graph export "fig/figure`k'.png", replace
}
else if `k'==2|`k'==4|`k'==6{
twoway  (line    estimates_mid                 month    , lcolor(gs3) ) ///
				(scatter estimates_mid                 month    , mcolor(gs3) ) ///
				(rcap    estimates_low estimates_upp   month    , lcolor(gs3) ) ///
				, ylabel(-.5(.1).5) ///
				xlabel(1(1)11) xtitle("month") yline(0) ///
				legend(order(2 "Treatment coef." 5 "90% confidence interval") ring(0) ) ///
				graphregion(color(white))
graph export "fig/figure`k'.png", replace
}
}


**** FIGURES A.3**********


use "data/Base_ADM_preparada_Long", clear

gen var1 = ContributedVol
gen var2 = ihs_cot_vol
gen var3 = Contributed
gen var4 = ihs_cot_obli
gen var5 = pensionado
gen var6 = ihs_savings
gen treat = (Tratamiento == 1)
gen month = date_dev - periodo_exp

estimates clear



sort ID1 month
xtset ID1 month

* Regression months. Each of these regressions should have N=2547
forvalues k=1/6{
forvalues i = 1/11 {

	* outcome mean for control group, months 1 to 6 post treatment
	estpost summarize var`k' if Tratamiento == 0 & month == `i'
	if abs(el(e(mean),1,1))>100{
		local mean_var`k'_`i': di %12.0fc el(e(mean),1,1)
		}
	else{
		local mean_var`k'_`i': di %12.3fc el(e(mean),1,1)
		}
		local mean_var`k'_`i' = 0

	* regression
	areg var`k' Tratamiento L12.(var`k') if month == `i', a(periodo_exp) robust
	local N_var`k': di %12.0fc e(N)

	foreach x in Tratamiento {
		test `x'
		local s_var`k'_`i'=cond(r(p)<.01,"***",cond(r(p)<.05,"**",cond(r(p)<.1,"*","")))
		if abs(_b[`x'])>100{
			local b_var`k'_`i': di %12.0fc _b[`x']
			}
		else{
			local b_var`k'_`i': di %12.3fc _b[`x']
			}
		if abs(_se[`x'])>100{
			local se_var`k'_`i': di %12.0fc _se[`x']
			}
		else{
			local se_var`k'_`i': di %12.3fc _se[`x']
			}
	}
}
}
* Make matrix for graph
matrix control		   = J(11,1,.)
matrix estimates_mid = J(11,1,.)
matrix estimates_upp = J(11,1,.)
matrix estimates_low = J(11,1,.)
forvalues k= 1/6{
forvalues j = 1/11 {
matrix estimates_mid[`j',1] = `b_var`k'_`j''
  matrix estimates_upp[`j',1] = `b_var`k'_`j'' +  1.645*`se_var`k'_`j''
  matrix estimates_low[`j',1] = `b_var`k'_`j'' -  1.645*`se_var`k'_`j''
}
* Generate graph date
clear
svmat double control, name(control)
rename control1 control
svmat double estimates_mid, name(estimates_mid)
rename estimates_mid1 estimates_mid
svmat double estimates_upp, name(estimates_upp)
rename estimates_upp1 estimates_upp
svmat double estimates_low, name(estimates_low)
rename estimates_low1 estimates_low
* graph
gen month = _n
if `k'==1|`k'==3|`k'==5{
twoway  (line    estimates_mid                 month    , lcolor(gs3) ) ///
				(scatter estimates_mid                 month    , mcolor(gs3) ) ///
				(rcap    estimates_low estimates_upp   month    , lcolor(gs3) ) ///
				, ylabel(-.05(.01).05) ///
				xlabel(1(1)11) xtitle("month") yline(0) ///
				legend(order(2 "Treatment coef." 5 "90% confidence interval") ring(0) ) ///
				graphregion(color(white))
graph export "fig/figure`k'_sc.png", replace
}
else if `k'==2|`k'==4|`k'==6{
twoway  (line    estimates_mid                 month    , lcolor(gs3) ) ///
				(scatter estimates_mid                 month    , mcolor(gs3) ) ///
				(rcap    estimates_low estimates_upp   month    , lcolor(gs3) ) ///
				, ylabel(-.5(.1).5) ///
				xlabel(1(1)11) xtitle("month") yline(0) ///
				legend(order(2 "Treatment coef." 5 "90% confidence interval") ring(0) ) ///
				graphregion(color(white))
graph export "fig/figure`k'_sc.png", replace
}
}


***FIGURES A.2*******

use "data/Base_ADM_preparada_Long", clear

gen var1 = ContributedVol
gen var2 = ihs_cot_vol
gen var3 = Contributed
gen var4 = ihs_cot_obli
gen var5 = pensionado
gen var6 = ihs_savings
gen treat = (Tratamiento == 1)
gen month = date_dev - periodo_exp

estimates clear



sort ID1 month
xtset ID1 month

foreach var of varlist $Controles1 {
	gen `var'_miss = (`var'==.)
	replace `var' = 0 if `var'==.
	tab month `var'_miss
	* global Controles1 $Controles1 `var'_miss
}

* Regression months. Each of these regressions should have N=2547
forvalues k=1/6{
forvalues i = 1/11 {

	* outcome mean for control group, months 1 to 6 post treatment
	estpost summarize var`k' if Tratamiento == 0 & month == `i'
	if abs(el(e(mean),1,1))>100{
		local mean_var`k'_`i': di %12.0fc el(e(mean),1,1)
		}
	else{
		local mean_var`k'_`i': di %12.3fc el(e(mean),1,1)
		}
		local mean_var`k'_`i' = 0

		
	* regression
	areg var`k' Tratamiento L12.(var`k' edad Working saldo_uf rem_actual edad_miss Working_miss saldo_uf_miss rem_actual_miss) if month == `i', a(periodo_exp) robust
	local N_var`k': di %12.0fc e(N)

	foreach x in Tratamiento {
		test `x'
		local s_var`k'_`i'=cond(r(p)<.01,"***",cond(r(p)<.05,"**",cond(r(p)<.1,"*","")))
		if abs(_b[`x'])>100{
			local b_var`k'_`i': di %12.0fc _b[`x']
			}
		else{
			local b_var`k'_`i': di %12.3fc _b[`x']
			}
		if abs(_se[`x'])>100{
			local se_var`k'_`i': di %12.0fc _se[`x']
			}
		else{
			local se_var`k'_`i': di %12.3fc _se[`x']
			}
	}
}
}
* Make matrix for graph
matrix control		   = J(11,1,.)
matrix estimates_mid = J(11,1,.)
matrix estimates_upp = J(11,1,.)
matrix estimates_low = J(11,1,.)
forvalues k= 1/6{
forvalues j = 1/11 {
matrix estimates_mid[`j',1] = `b_var`k'_`j''
  matrix estimates_upp[`j',1] = `b_var`k'_`j'' +  1.645*`se_var`k'_`j''
  matrix estimates_low[`j',1] = `b_var`k'_`j'' -  1.645*`se_var`k'_`j''
}
* Generate graph date
clear
svmat double control, name(control)
rename control1 control
svmat double estimates_mid, name(estimates_mid)
rename estimates_mid1 estimates_mid
svmat double estimates_upp, name(estimates_upp)
rename estimates_upp1 estimates_upp
svmat double estimates_low, name(estimates_low)
rename estimates_low1 estimates_low
* graph
gen month = _n
if `k'==1|`k'==3|`k'==5{
twoway  (line    estimates_mid                 month    , lcolor(gs3) ) ///
				(scatter estimates_mid                 month    , mcolor(gs3) ) ///
				(rcap    estimates_low estimates_upp   month    , lcolor(gs3) ) ///
				, ylabel(-.05(.01).05) ///
				xlabel(1(1)11) xtitle("month") yline(0) ///
				legend(order(2 "Treatment coef." 5 "90% confidence interval") ring(0) ) ///
				graphregion(color(white))
graph export "fig/figure`k'_lc.png", replace
}
else if `k'==2|`k'==4|`k'==6{
twoway  (line    estimates_mid                 month    , lcolor(gs3) ) ///
				(scatter estimates_mid                 month    , mcolor(gs3) ) ///
				(rcap    estimates_low estimates_upp   month    , lcolor(gs3) ) ///
				, ylabel(-.5(.1).5) ///
				xlabel(1(1)11) xtitle("month") yline(0) ///
				legend(order(2 "Treatment coef." 5 "90% confidence interval") ring(0) ) ///
				graphregion(color(white))
graph export "fig/figure`k'_lc.png", replace
}
}


****TABLE 2**********

use "data/Encuesta_SEG_Preparada", clear

label var Seguimiento "Follow-up"
label var Tratamiento "Pers. info"

* Section 1:
global p2_s1 p2_s1_contrib p2_s1_aument p2_s1_simul p2_s1_nosabe
global S1 p1_s1 p2_s1 $p2_s1 p4_s1

* Section 2:
global S2 p1_s2 p3_s2 p4_s2_contr p5_s2_correct p6_s2 p7_s2_correct

* Section 3:
global S3 p1_s6 p2_s6 p3_s6

* All:
global AllSEG $S1 $S2 $S3

* Categories/heading for variables with more than 1 alternative:
label var p2_s1 "Information Received:"
label var p3_s1 "Information Received (specific):"
label var p4_s2 "How are pensions calculated:"
label var p1_s3 "During the last year, considered:"
label var p2_s3 "During the last year:"
label var p3_s3 "What motivated this changes:"
label var p4_s3 "Reasons for not thinking in making changes:"
label var p1_s4 "Labor situation"
label var p3_s5 "Where are those savings:"
label var p6_s5 "Expected income source after retirement:"
label var p7_s5 "How to complement savings after retirement:"
replace p4_s2 = .
replace p2_s1 = .
replace p6_s5 = .
replace p7_s5 = .

forvalues k = 1/1 {
foreach var of varlist $AllSEG {

qui sum `var'
local NC_`var' = r(N)

if `NC_`var'' != 0 {
	
	areg `var' Tratamiento ${Controles`k'}, a(periodo_exp) robust
    
		test Tratamiento
		local N_`var': di %12.0fc e(N)
		local s_Trat`var'=cond(r(p)<.01,"***",cond(r(p)<.05,"**",cond(r(p)<.1,"*","")))	 
		local b_Trat`var': di %12.3fc _b[Trat]
		local se_Trat`var': di %12.3fc _se[Trat]	
	
		sum `var' if Tratamiento == 0
		local CM`var': di %12.3fc r(mean)
		local SD`var': di %12.3fc r(sd)
}
}

{
texdoc init tab/results_survey.tex, replace force
tex \begin{longtable}{lccc} \hline
	tex Variables			&     N     & Control Mean & Impact of personalized info.	        \\
	tex \hline \endhead

	forvalues i = 1/3 {
	if `i' == 1 {
	tex \textbf{Recall:} \\
	}
	if `i' == 2 {
	tex \textbf{Knowledge:} \\
	}
	if `i' == 3 {
	tex \textbf{AFP's valuation:} \\
	}
	local secc "S`i'"
	foreach var in $`secc' {
	if `NC_`var'' != 0 {
	tex `: var label `var'' & `N_`var'' & `CM`var'' & `b_Trat`var''`s_Trat`var'' \\
	tex                     &           &  (`SD`var'')     & (`se_Trat`var'')           \\
	}
	else {
	tex \textit{`: var label `var''} \\
	}
	}
}

tex \\ \hline

tex \end{longtable}
texdoc close
}
}


****FIGURE 7****
*** RESULTS FROM THE TABLE WERE PRESENTED IN A GRAPH*

use "data/Base_ADM_preparada_Long.dta", clear

xtset ID1 Months
gen treat = Tratamiento
gen month = date_dev - periodo_exp

foreach var of varlist $Controles1 {
  gen `var'_miss = (`var'==.)
  replace `var' = 0 if `var'==.
  tab month `var'_miss
  * global Controles1 $Controles1 `var'_miss
}

gen var0 = ihs_savings
gen var1 = ContributedVol
gen var2 = ihs_cot_vol
gen var3 = Contributed
gen var4 = ihs_cot_obli
gen var5 = pensionado

global OutcomesADM_Resumen var0 var1 var2 var3 var4 var5

replace ErrorPension = ErrorPension/(res_sim_1+esperada_pens)
replace ErrorPension = 0 if res_sim_1==0 & esperada_pens==0

gen Err_1=ErrorPension<-0.55 if ErrorPension~=.
gen Err_2 = -0.55 <= ErrorPension & ErrorPension < -0.1 if ErrorPension ~=. & ErrorPension>-1
gen Err_3 = -0.1  <= ErrorPension & ErrorPension < 0.1 if ErrorPension~=.
gen Err_4 = 0.1 <= ErrorPension & ErrorPension<0.35 if ErrorPension~=.
gen Err_5 = 0.35 <= ErrorPension if ErrorPension ~= .


forvalues i=1/5{
gen treat`i'=Tratamiento*Err_`i'
}

label var treat1 "Overest. Pension $>$ 55\%"
label var treat2 "Overest. Pension 55\% $>$ 10\%"
label var treat3 "Overest. Pension 10\% $>$ 10\%"
label var treat4 "Underest. Pension 10\% $>$ 35\%"
label var treat5 "Underest. Pension $>$ 35\%"


********************************************************************************

foreach var of varlist $OutcomesADM_Resumen {


  * outcome mean for control group, months 1 to 6 post treatment
  estpost summarize `var' if Tratamiento == 0 & month>=1 & month<=6		// post == 3 means months 1 to 6 post treatment
  if abs(el(e(mean),1,1))>100{
    local mean_`var': di %12.0fc el(e(mean),1,1)
    }
  else{
    local mean_`var': di %12.3fc el(e(mean),1,1)
    }



  * regression
  forvalues i=1/5{
  sum var2 if Err_`i'==1 & month==1
local N_var2_`i': di %12.0fc r(N)
}
    areg `var' treat1 treat2 treat3 treat4 treat5 Err_* L12.(`var' $Controles1) if month>=1 & month<=6, a(periodo_exp) vce(cluster ID1)
	forvalues i=1/5{
      test treat`i'
      local s_`var'_treat`i'=cond(r(p)<.01,"***",cond(r(p)<.05,"**",cond(r(p)<.1,"*","")))
      if abs(_b[treat`i'])>100{
        local b_`var'_treat`i': di %12.0fc _b[treat`i']
        }
      else{
        local b_`var'_treat`i': di %12.3fc _b[treat`i']
        }
      if abs(_se[treat`i'])>100{
        local se_`var'_treat`i': di %12.0fc _se[treat`i']
        }
      else{
        local se_`var'_treat`i': di %12.3fc _se[treat`i']
        }
      
  }
}


texdoc init tab\het_mistake.tex, replace
tex \documentclass[11pt]{article}
tex \input{Preamble.tex}
tex \begin{document}
tex
tex \begin{table}[h!]
tex \caption{"Impact on actual savings."}
tex \label{tab:table5}
tex \begin{center}
  tex \begin{tabular}{p{6cm}ccccccc}
  tex \toprule
  tex 						&	\multicolumn{1}{c}{Savings Sum} 								&	\multicolumn{2}{c}{Voluntary savings} 								&& \multicolumn{2}{c}{Mandatory savings}  								& \multicolumn{1}{c}{}				\\
  tex \cline{3-4} \cline{6-7}
  tex 						&	\multicolumn{1}{c}{vol.} 		&	\multicolumn{1}{c}{num.} 		&	\multicolumn{1}{c}{vol.} 		&& \multicolumn{1}{c}{num.}			& \multicolumn{1}{c}{vol.}  		& \multicolumn{1}{c}{Retired}		\\
  tex \midrule
  forvalues x=1/5 {
  tex   `:var label treat`x'' 		& `b_var0_treat`x''`s_var0_treat`x''	& `b_var1_treat`x''`s_var1_treat`x''	& `b_var2_treat`x''`s_var2_treat`x''			&&	`b_var3_treat`x''`s_var3_treat`x''		& `b_var4_treat`x''`s_var4_treat`x''			& `b_var5_treat`x''`s_var5_treat`x''			\\
  tex    N people=`N_var2_`x''           & (`se_var0_treat`x'')       			    & (`se_var1_treat`x'')       			    & (`se_var2_treat`x'') 					&&   (`se_var3_treat`x'')				& (`se_var4_treat`x'')					& (`se_var5_treat`x'')					\\
  }
  tex Control Mean			          &	`mean_var0'						              &	`mean_var1'						              &	`mean_var2'						&&	`mean_var3'						&	`mean_var4'						&	`mean_var5'						\\
  tex \bottomrule
  tex \multicolumn{8}{p{17cm}}{\quad \footnotesize Robust standard errors in parentheses. Sample size is 2,547 people for 6 months s.t. N = 15 282. Regressions include all variables in Table 1 as covariates. *** p<0.01 ** p<0.05 * p<0.1} \\
  tex \end{tabular}
tex \end{center}
tex \end{table}
tex
tex \end{document}
texdoc close


*** RESULTS REFERRED TO IN SECTION 4.2 BUT NOT PRESENTED


forvalues m=1/3{
use "data/Base_ADM_preparada_Long", clear

gen var1 = ContributedVol
gen var2 = ihs_cot_vol
gen var3 = Contributed
gen var4 = ihs_cot_obli
gen var5 = pensionado
gen var6 = ihs_savings
gen treat = (Tratamiento == 1)
gen month = date_dev - periodo_exp

estimates clear

replace ErrorPension = ErrorPension/(res_sim_1+esperada_pens)
replace ErrorPension = 0 if res_sim_1==0 & esperada_pens==0

gen Err_1=ErrorPension< -0.1 if ErrorPension ~=.
gen Err_2 = -0.1  <= ErrorPension & ErrorPension < 0.1 if ErrorPension~=.
gen Err_3 = 0.1 <= ErrorPension  if ErrorPension~=.

keep if Err_`m'==1

sort ID1 month
xtset ID1 month

foreach var of varlist $Controles1 {
	gen `var'_miss = (`var'==.)
	replace `var' = 0 if `var'==.
	tab month `var'_miss
	* global Controles1 $Controles1 `var'_miss
}

* Regression months. Each of these regressions should have N=2547
forvalues k=1/6{
forvalues i = 1/11 {


	* outcome mean for control group, months 1 to 6 post treatment
	estpost summarize var`k' if Tratamiento == 0 & month == `i'
	if abs(el(e(mean),1,1))>100{
		local mean_var`k'_`i': di %12.0fc el(e(mean),1,1)
		}
	else{
		local mean_var`k'_`i': di %12.3fc el(e(mean),1,1)
		}
		local mean_var`k'_`i' = 0

	* regression
	areg var`k' Tratamiento L12.(var`k' $Controles1) if month == `i', a(periodo_exp) robust
	local N_var`k': di %12.0fc e(N)

	foreach x in Tratamiento {
		test `x'
		local s_var`k'_`i'=cond(r(p)<.01,"***",cond(r(p)<.05,"**",cond(r(p)<.1,"*","")))
		if abs(_b[`x'])>100{
			local b_var`k'_`i': di %12.0fc _b[`x']
			}
		else{
			local b_var`k'_`i': di %12.3fc _b[`x']
			}
		if abs(_se[`x'])>100{
			local se_var`k'_`i': di %12.0fc _se[`x']
			}
		else{
			local se_var`k'_`i': di %12.3fc _se[`x']
			}
	}
}
}
* Make matrix for graph
matrix control		   = J(11,1,.)
matrix estimates_mid = J(11,1,.)
matrix estimates_upp = J(11,1,.)
matrix estimates_low = J(11,1,.)
forvalues k= 1/6{
forvalues j = 1/11 {
matrix estimates_mid[`j',1] = `b_var`k'_`j''
  matrix estimates_upp[`j',1] = `b_var`k'_`j'' +  1.645*`se_var`k'_`j''
  matrix estimates_low[`j',1] = `b_var`k'_`j'' -  1.645*`se_var`k'_`j''
}
* Generate graph date
clear
svmat double control, name(control)
rename control1 control
svmat double estimates_mid, name(estimates_mid)
rename estimates_mid1 estimates_mid
svmat double estimates_upp, name(estimates_upp)
rename estimates_upp1 estimates_upp
svmat double estimates_low, name(estimates_low)
rename estimates_low1 estimates_low
* graph
gen month = _n
if `k'==1|`k'==3|`k'==5{
twoway  (line    estimates_mid                 month    , lcolor(gs3) ) ///
				(scatter estimates_mid                 month    , mcolor(gs3) ) ///
				(rcap    estimates_low estimates_upp   month    , lcolor(gs3) ) ///
				, ylabel(-.05(.01).05) ///
				xlabel(1(1)11) xtitle("month") yline(0) ///
				legend(order(2 "Treatment coef." 5 "90% confidence interval") ring(0) ) ///
				graphregion(color(white))
graph export "fig/figure`k'_Err`m'.png", replace
}
else if `k'==2|`k'==4|`k'==6{
twoway  (line    estimates_mid                 month    , lcolor(gs3) ) ///
				(scatter estimates_mid                 month    , mcolor(gs3) ) ///
				(rcap    estimates_low estimates_upp   month    , lcolor(gs3) ) ///
				, ylabel(-.5(.1).5) ///
				xlabel(1(1)11) xtitle("month") yline(0) ///
				legend(order(2 "Treatment coef." 5 "90% confidence interval") ring(0) ) ///
				graphregion(color(white))
graph export "fig/figure`k'_Err`m'.png", replace
}
}
}

**** TABLE 3*********

use "data/Encuesta_SEG_Preparada", clear

* Section 1:
global p1_s3 p1_1_s3_afilia p1_2_s3 p1_3_s3 p1_4_s3 p1_5_s3
global S1 p1_s3 $p1_s3 

* Section 2:
global S2 p1_s5 ln_p2_s5 p5_s5_import 

*Section 4:
global S3 p1_s6 p2_s6 p3_s6

* All:
global TodoSEG $S1 $S2 $S3

********************************************************************************

* Categories/heading for variables with more than 1 alternative:
label var p1_2_s3 "Started/increased vol. savings"
label var p1_3_s3 "Changing cont. freq."
label var p1_4_s3 "Changing retirement age"
label var p1_5_s3 "Informing about system"
label var p5_s4_salud "Health insurance (public/priv.)"
label var p2_s1 "Information Received:"
label var p3_s1 "Information Received (specific):"
label var p4_s2 "How are pensions calculated:"
label var p1_s3 "During the last year considered:"
label var p2_s3 "During the last year:"
label var p3_s3 "What motivated this changes:"
label var p4_s3 "Reasons for not thinking in making changes:"
label var p1_s4 "Labor situation"
label var p3_s5 "Where are those savings:"
label var p6_s5 "Expected income source after retirement:"
label var p7_s5 "How to complement savings after retirement:"
replace p4_s2 = . 
replace p2_s1 = .
replace p6_s5 = .
replace p7_s5 = .

********************************************************************************

replace ErrorPension = ErrorPension/(res_sim_1+esperada_pens)
gen Err_1 = ErrorPension < -0.15                       if ErrorPension ~= .
gen Err_2 = -0.15 <= ErrorPension & ErrorPension < 0.15 if ErrorPension ~= .
gen Err_3 = ErrorPension >= 0.15                       if ErrorPension ~= .
gen inter1 = Tratamiento*Err_1
gen inter2 = Tratamiento*Err_2
gen inter3 = Tratamiento*Err_3


label var inter1 "\shortstack{Pers. Info.\\*Overest. $>$ 15\%}"
label var inter2 "\shortstack{Pers. Info.\\*Est. within 15\%}"
label var inter3 "\shortstack{Pers. Info.\\*Underest. $>$ 15\%}"

********************************************************************************

foreach var of varlist $TodoSEG {

qui sum `var'
local NC_`var' = r(N)

if `NC_`var'' != 0 {
	
	areg `var' inter1 inter2 inter3 Err_2 Err_3 ${Controles1}, a(periodo_exp) robust
    
	foreach coef in inter1 inter2 inter3 {
		test `coef'
		local N_`var': di %12.0fc e(N)
		local s_`coef'`var'=cond(r(p)<.01,"***",cond(r(p)<.05,"**",cond(r(p)<.1,"*","")))	 
		local b_`coef'`var': di %12.3fc _b[`coef']
		local se_`coef'`var': di %12.2fc _se[`coef']
	}
	
	sum `var' if Tratamiento == 0
	local CM`var': di %12.3fc r(mean)
}
}

{
texdoc init tab\het_mistake_survey.tex, replace force

tex \begin{longtable}{lccccc} \hline
	tex Variables			&     N     & Control Mean & `: var label inter1' & `: var label inter2' & `: var label inter3' \\
	tex \midrule \endhead

	forvalues i = 1/3 {
	if `i' == 1 {
	tex \textbf{Behavior:} \\
	}
	if `i' == 2 {
	tex \textbf{Savings:} \\
	}
	if `i' == 3 {
	tex \textbf{AFP's valuation:} \\
	}
	
	local secc "S`i'"
	foreach var in $`secc' {
	if `NC_`var'' != 0 { 
	tex `: var label `var'' & `N_`var'' & `CM`var'' & `b_inter1`var''`s_inter1`var'' & `b_inter2`var''`s_inter2`var'' & `b_inter3`var''`s_inter3`var'' \\
	tex                     &           &           & (`se_inter1`var'')             & (`se_inter2`var'')             & (`se_inter3`var'')             \\
	}
	}
	else {
	tex \textit{`: var label `var''} \\
	}
	}

tex \\ \bottomrule
tex \end{longtable}
texdoc close
}


****TABLE A.4*************

use "data/Base_ADM_preparada_Long.dta", clear

  merge m:1 ID1 ID2 using "src/sim_v2.dta"
  keep if _merge==3
  drop _merge

xtset ID1 Months
gen treat = Tratamiento
gen month = date_dev - periodo_exp

foreach var of varlist $Controles1 {
  gen `var'_miss = (`var'==.)
  replace `var' = 0 if `var'==.
  tab month `var'_miss
  * global Controles1 $Controles1 `var'_miss
}

gen var6 = ihs_savings
gen var1 = ContributedVol
gen var2 = ihs_cot_vol
gen var3 = Contributed
gen var4 = ihs_cot_obli
gen var5 = pensionado

global OutcomesADM_Resumen var6 var1 var2 var3 var4 var5

gen premio_dens	=	(sv2_pension_dens-sv2_pension)/sv2_pension
gen premio_apv	=	(sv2_pension_apv-sv2_pension)/sv2_pension
gen premio_jub	=	(sv2_pension_jub-sv2_pension)/sv2_pension

gen Err_1 = premio_apv	>= premio_dens	& premio_apv  >= premio_jub	if sv2_pension~=.	// apv_best
gen Err_2 = premio_dens >  premio_apv	& premio_dens >= premio_jub	if sv2_pension~=.	// dens_best
gen Err_3 = premio_jub	>  premio_dens	& premio_jub  >  premio_apv	if sv2_pension~=.	// jub_best

gen Treat1=Tratamiento*Err_1
gen Treat2=Tratamiento*Err_2
gen Treat3=Tratamiento*Err_3

label var Treat1 "T*voluntary contributions more important"
label var Treat2 "T*increasing density more important"
label var Treat3 "T*delaying retirement more important"




********************************************************************************

foreach var of varlist $OutcomesADM_Resumen {


  * outcome mean for control group, months 1 to 6 post treatment
  estpost summarize `var' if Tratamiento == 0 & month>=1 & month<=6		// post == 3 means months 1 to 6 post treatment
  if abs(el(e(mean),1,1))>100{
    local mean_`var': di %12.0fc el(e(mean),1,1)
    }
  else{
    local mean_`var': di %12.3fc el(e(mean),1,1)
    }



  * regression
 forvalues i=1/3{
  sum var2 if Err_`i'==1 & month==1
local N_Treat`i': di %12.0fc r(N)
}

    areg `var' Treat1 Treat2 Treat3 Err_* L12.(`var' $Controles1) if month>=1 & month<=6, a(periodo_exp) vce(cluster ID1)
	forvalues i=1/3{
      test Treat`i'
      local s_`var'_Treat`i'=cond(r(p)<.01,"***",cond(r(p)<.05,"**",cond(r(p)<.1,"*","")))
      if abs(_b[Treat`i'])>100{
        local b_`var'_Treat`i': di %12.0fc _b[Treat`i']
        }
      else{
        local b_`var'_Treat`i': di %12.3fc _b[Treat`i']
        }
      if abs(_se[Treat`i'])>100{
        local se_`var'_Treat`i': di %12.0fc _se[Treat`i']
        }
      else{
        local se_`var'_Treat`i': di %12.3fc _se[Treat`i']
        }
      
  }
}


* Generate Table 7
texdoc init tab\table7.tex, replace
tex \documentclass[11pt]{article}
tex \input{Preamble.tex}
tex \begin{document}
tex
tex \begin{table}[h!]
tex \caption{"Impact of Personalized Information on behavior within the pension system, by type of message, first 6 months."}
tex \label{tab:table7}
tex \begin{center}
	tex \begin{tabular}{p{5cm}cccccccc}
	tex \toprule
	tex 						& Total savings &	\multicolumn{2}{c}{Voluntary savings} 								& \multicolumn{2}{c}{Mandatory savings}  								& \multicolumn{1}{c}{}				&\\
	tex \cline{3-4} \cline{5-6}
	tex First best				&  &	\multicolumn{1}{c}{num.} 		&	\multicolumn{1}{c}{vol.} 		& \multicolumn{1}{c}{num.}			& \multicolumn{1}{c}{vol.}  		& \multicolumn{1}{c}{Retired}		& \multicolumn{1}{c}{Obs.}		\\
	tex \midrule
	foreach x in Treat1 Treat2 Treat3 {
	tex   `:var label `x'' 		& `b_var6_`x''`s_var6_`x'' & `b_var1_`x''`s_var1_`x''			& `b_var2_`x''`s_var2_`x''			&	`b_var3_`x''`s_var3_`x''		& `b_var4_`x''`s_var4_`x''			& `b_var5_`x''`s_var5_`x''			& `N_`x''		\\
	tex               			& (`se_var6_`x'') & (`se_var1_`x'')       			& (`se_var2_`x'') 					&   (`se_var3_`x'')				& (`se_var4_`x'')					& (`se_var5_`x'')					&\\
	}
	tex \\
	tex Control Mean			& `mean_var6'&	`mean_var1'						&	`mean_var2'						&	`mean_var3'						&	`mean_var4'						&	`mean_var5'						&\\
	tex \bottomrule
	tex \multicolumn{8}{p{15cm}}{\quad \footnotesize Robust standard errors in parentheses. Sample size is N=2,405 for each outcome. Regressions include exposition period fixed effects and controls by gender, educational level, income, simulated pension and whether the person is head of household. *** p<0.01 ** p<0.05 * p<0.1} \\
	tex \end{tabular}
tex \end{center}
tex \end{table}
tex
tex \end{document} 
texdoc close

clear

*****TABLE 5*****

use "data/Base_ADM_preparada_Long.dta", clear

  merge m:1 ID1 ID2 using "src/sim_v2.dta"
  keep if _merge==3
  drop _merge

xtset ID1 Months
gen treat = Tratamiento
gen month = date_dev - periodo_exp

foreach var of varlist $Controles1 {
  gen `var'_miss = (`var'==.)
  replace `var' = 0 if `var'==.
  tab month `var'_miss
  * global Controles1 $Controles1 `var'_miss
}

gen var6 = ihs_savings
gen var1 = ContributedVol
gen var2 = ihs_cot_vol
gen var3 = Contributed
gen var4 = ihs_cot_obli
gen var5 = pensionado

global OutcomesADM_Resumen var6 var1 var2 var3 var4 var5

gen premio_dens	=	(sv2_pension_dens-sv2_pension)/sv2_pension
gen premio_apv	=	(sv2_pension_apv-sv2_pension)/sv2_pension
gen premio_jub	=	(sv2_pension_jub-sv2_pension)/sv2_pension

gen Err_1 = premio_apv	>= 0.1 if sv2_pension~=.
gen Err_2 = premio_dens > 0  if sv2_pension~=.	// dens_best
gen Err_3 = premio_jub	>= 0.08	if sv2_pension~=.	// jub_best

gen Treat11=Tratamiento*Err_1
gen Treat10=Tratamiento*(1-Err_1)
gen Treat21=Tratamiento*Err_2
gen Treat20=Tratamiento*(1-Err_2)
gen Treat31=Tratamiento*Err_3
gen Treat30=Tratamiento*(1-Err_3)

label var Treat11 "T*large increase from vol. savings"
label var Treat10 "T*small increase from vol. savings"
label var Treat21 "T*positive increase from density"
label var Treat20 "T*no increase from density"
label var Treat31 "T*large increase from delaying ret."
label var Treat30 "T*small increase from delaying ret."




********************************************************************************

foreach var of varlist $OutcomesADM_Resumen {


  * regression
 forvalues i=1/3{
    areg `var' Treat`i'1 Treat`i'0 Err_`i' L12.(`var' $Controles1) if month>=1 & month<=6, a(periodo_exp) vce(cluster ID1)
      test Treat`i'1
      local s_`var'_Treat`i'1=cond(r(p)<.01,"***",cond(r(p)<.05,"**",cond(r(p)<.1,"*","")))
      if abs(_b[Treat`i'1])>100{
        local b_`var'_Treat`i'1: di %12.0fc _b[Treat`i'1]
        }
      else{
        local b_`var'_Treat`i'1: di %12.3fc _b[Treat`i'1]
        }
      if abs(_se[Treat`i'1])>100{
        local se_`var'_Treat`i'1: di %12.0fc _se[Treat`i'1]
        }
      else{
        local se_`var'_Treat`i'1: di %12.3fc _se[Treat`i'1]
        }
            test Treat`i'0
      local s_`var'_Treat`i'0=cond(r(p)<.01,"***",cond(r(p)<.05,"**",cond(r(p)<.1,"*","")))
      if abs(_b[Treat`i'1])>100{
        local b_`var'_Treat`i'0: di %12.0fc _b[Treat`i'0]
        }
      else{
        local b_`var'_Treat`i'0: di %12.3fc _b[Treat`i'0]
        }
      if abs(_se[Treat`i'1])>100{
        local se_`var'_Treat`i'0: di %12.0fc _se[Treat`i'0]
        }
      else{
        local se_`var'_Treat`i'0: di %12.3fc _se[Treat`i'0]
        }
      
  }
}


* Generate Table 7
texdoc init tab\table7c.tex, replace
tex \documentclass[11pt]{article}
tex \input{Preamble.tex}
tex \begin{document}
tex
tex \begin{table}[h!]
tex \caption{"Impact of Personalized Information on behavior within the pension system, by type of message, first 6 months."}
tex \label{tab:table7}
tex \begin{center}
	tex \begin{tabular}{p{5cm}ccccccc}
	tex \toprule
	tex 						& Total savings &	\multicolumn{2}{c}{Voluntary savings} 								& \multicolumn{2}{c}{Mandatory savings}  								&\\
	tex \cline{3-4} \cline{5-6}
	tex 				&  &	\multicolumn{1}{c}{num.} 		&	\multicolumn{1}{c}{vol.} 		& \multicolumn{1}{c}{num.}			& \multicolumn{1}{c}{vol.}  		& \multicolumn{1}{c}{Retired}\\
	tex \midrule
	foreach x in Treat1 Treat2 Treat3 {
	tex   `:var label `x'0' 		& `b_var6_`x'0'`s_var6_`x'0' & `b_var1_`x'0'`s_var1_`x'0'			& `b_var2_`x'0'`s_var2_`x'0'			&	`b_var3_`x'0'`s_var3_`x'0'		& `b_var4_`x'0'`s_var4_`x'0'			& `b_var5_`x'0'`s_var5_`x'0'		\\
	tex               			& (`se_var6_`x'0') & (`se_var1_`x'0')       			& (`se_var2_`x'0') 					&   (`se_var3_`x'0')				& (`se_var4_`x'0')					& (`se_var5_`x'0')			\\
	tex   `:var label `x'1' 		& `b_var6_`x'1'`s_var6_`x'1' & `b_var1_`x'1'`s_var1_`x'1'			& `b_var2_`x'1'`s_var2_`x'1'			&	`b_var3_`x'1'`s_var3_`x'1'		& `b_var4_`x'1'`s_var4_`x'1'			& `b_var5_`x'1'`s_var5_`x'1'		\\
	tex               			& (`se_var6_`x'1') & (`se_var1_`x'1')       			& (`se_var2_`x'1') 					&   (`se_var3_`x'1')				& (`se_var4_`x'1')					& (`se_var5_`x'1')			\\
	}
	tex \\
	tex \bottomrule
	tex \multicolumn{8}{p{15cm}}{\quad \footnotesize Robust standard errors in parentheses. Sample size is N=2,405 for each outcome. Regressions include exposition period fixed effects and controls by gender, educational level, income, simulated pension and whether the person is head of household. *** p<0.01 ** p<0.05 * p<0.1} \\
	tex \end{tabular}
tex \end{center}
tex \end{table}
tex
tex \end{document} 
texdoc close

clear


****TABLE 6*******

use "data/Base_ADM_preparada_Long.dta", clear

  merge m:1 ID1 ID2 using "src/sim_v2.dta"
  keep if _merge==3
  drop _merge

xtset ID1 Months
gen treat = Tratamiento
gen month = date_dev - periodo_exp

foreach var of varlist $Controles1 {
  gen `var'_miss = (`var'==.)
  replace `var' = 0 if `var'==.
  tab month `var'_miss
  * global Controles1 $Controles1 `var'_miss
}

gen var6 = ihs_savings
gen var1 = ContributedVol
gen var2 = ihs_cot_vol
gen var3 = Contributed
gen var4 = ihs_cot_obli
gen var5 = pensionado

global OutcomesADM_Resumen var6 var1 var2 var3 var4 var5

gen premio_dens	=	(sv2_pension_dens-sv2_pension)/sv2_pension
gen premio_apv	=	(sv2_pension_apv-sv2_pension)/sv2_pension
gen premio_jub	=	(sv2_pension_jub-sv2_pension)/sv2_pension

egen premio_max=rmax(premio_dens premio_apv premio_jub)

replace ErrorPension = ErrorPension/(res_sim_1+esperada_pens)
gen Err_1 = ErrorPension < -0.15                       if ErrorPension ~= .
gen Err_2 = -0.15 <= ErrorPension & ErrorPension < 0.15 if ErrorPension ~= .
gen Err_3 = ErrorPension >= 0.15                       if ErrorPension ~= .

gen Err_10 = Err_1*(premio_max<0.09) if premio_max~=.
gen Err_11 = Err_1*(premio_max>=0.09) if premio_max~=.	
gen Err_20 = Err_2*(premio_max<0.09) if premio_max~=.	
gen Err_21 = Err_2*(premio_max>=0.09) if premio_max~=.
gen Err_30 = Err_3*(premio_max<0.09) if premio_max~=.
gen Err_31 = Err_3*(premio_max>=0.09) if premio_max~=.

drop Err_1 Err_2 Err_3

gen Treat1=Tratamiento*Err_10
gen Treat2=Tratamiento*Err_11
gen Treat3=Tratamiento*Err_20
gen Treat4=Tratamiento*Err_21
gen Treat5=Tratamiento*Err_30
gen Treat6=Tratamiento*Err_31

label var Treat1 "T*overestimated pension*low possibilities"
label var Treat2 "T*overestimated pension*high possibilities"
label var Treat3 "T*pension well estimated*low possibilities"
label var Treat4 "T*pension well estimated*high possibilities"
label var Treat5 "T*underestimated pension*low possibilities"
label var Treat6 "T*underestimated pension*high possibilities"


********************************************************************************

foreach var of varlist $OutcomesADM_Resumen {


  * outcome mean for control group, months 1 to 6 post treatment
  estpost summarize `var' if Tratamiento == 0 & month>=1 & month<=6		// post == 3 means months 1 to 6 post treatment
  if abs(el(e(mean),1,1))>100{
    local mean_`var': di %12.0fc el(e(mean),1,1)
    }
  else{
    local mean_`var': di %12.3fc el(e(mean),1,1)
    }



  * regression
/* forvalues i=1/3{
  sum var2 if Err_`i'==1 & month==1
local N_Treat`i': di %12.0fc r(N)
}
*/


    areg `var' Treat1 Treat2 Treat3 Treat4 Treat5 Treat6 Err_* L12.(`var' $Controles1) if month>=1 & month<=6, a(periodo_exp) vce(cluster ID1)
	forvalues i=1/6{
      test Treat`i'
      local s_`var'_Treat`i'=cond(r(p)<.01,"***",cond(r(p)<.05,"**",cond(r(p)<.1,"*","")))
      if abs(_b[Treat`i'])>100{
        local b_`var'_Treat`i': di %12.0fc _b[Treat`i']
        }
      else{
        local b_`var'_Treat`i': di %12.3fc _b[Treat`i']
        }
      if abs(_se[Treat`i'])>100{
        local se_`var'_Treat`i': di %12.0fc _se[Treat`i']
        }
      else{
        local se_`var'_Treat`i': di %12.3fc _se[Treat`i']
        }
      
  }
}


* Generate Table 7
texdoc init tab\table7b.tex, replace
tex \documentclass[11pt]{article}
tex \input{Preamble.tex}
tex \begin{document}
tex
tex \begin{table}[h!]
tex \caption{"Impact of Personalized Information on behavior within the pension system, by how much pensions could be improved, first 6 months."}
tex \label{tab:table7}
tex \begin{center}
	tex \begin{tabular}{p{5cm}cccccccc}
	tex \toprule
	tex 						& Total savings &	\multicolumn{2}{c}{Voluntary savings} 								& \multicolumn{2}{c}{Mandatory savings}  								& \multicolumn{1}{c}{}				&\\
	tex \cline{3-4} \cline{5-6}
	tex First best				&  &	\multicolumn{1}{c}{num.} 		&	\multicolumn{1}{c}{vol.} 		& \multicolumn{1}{c}{num.}			& \multicolumn{1}{c}{vol.}  		& \multicolumn{1}{c}{Retired}		& \multicolumn{1}{c}{Obs.}		\\
	tex \midrule
	foreach x in Treat1 Treat2 Treat3 Treat4 Treat5 Treat6{
	tex   `:var label `x'' 		& `b_var6_`x''`s_var6_`x'' & `b_var1_`x''`s_var1_`x''			& `b_var2_`x''`s_var2_`x''			&	`b_var3_`x''`s_var3_`x''		& `b_var4_`x''`s_var4_`x''			& `b_var5_`x''`s_var5_`x''			& `N_`x''		\\
	tex               			& (`se_var6_`x'') & (`se_var1_`x'')       			& (`se_var2_`x'') 					&   (`se_var3_`x'')				& (`se_var4_`x'')					& (`se_var5_`x'')					&\\
	}
	tex \\
	tex Control Mean			& `mean_var6'&	`mean_var1'						&	`mean_var2'						&	`mean_var3'						&	`mean_var4'						&	`mean_var5'						&\\
	tex \bottomrule
	tex \multicolumn{8}{p{15cm}}{\quad \footnotesize Robust standard errors in parentheses. Sample size is N=2,405 for each outcome. Regressions include exposition period fixed effects and controls by gender, educational level, income, simulated pension and whether the person is head of household. *** p<0.01 ** p<0.05 * p<0.1} \\
	tex \end{tabular}
tex \end{center}
tex \end{table}
tex
tex \end{document} 
texdoc close

clear

****TABLE A.2****

clear

use "data/Base_ADM_TotalFinal", clear

foreach var in $OutcomesADM {

areg `var' Tratamiento if post == 1, a(periodo_exp) robust
est store `var'_nc

areg `var' Tratamiento L.`var' ${Controles1} if post == 1, a(periodo_exp) robust
est store `var'_cc
}


esttab *_nc using tab/table_otheroutcomes.tex , ///
	   keep(Tratamiento) stats(r2 N ControlMean, fmt(%9.3f %9.0gc %12.3f)) ///
	   cells(b(fmt(%9.3f) star) se(par fmt(%9.3f))) starlevels(* 0.10 ** 0.05 *** 0.01) label replace ///
	   note("Robust standard errors in parentheses. *** p$<$0.01 ** p$<$0.05 * p$<$0.1") ///
	   style(tex) booktabs nonumbers title("Panel A: Without controls")
	   
esttab *_cc using tab/table_otheroutcomes.tex , ///
	   keep(Tratamiento) stats(r2 N ControlMean, fmt(%9.3f %9.0gc %12.3f)) ///
	   cells(b(fmt(%9.3f) star) se(par fmt(%9.3f))) starlevels(* 0.10 ** 0.05 *** 0.01) label append ///
	   note("Robust standard errors in parentheses. *** p$<$0.01 ** p$<$0.05 * p$<$0.1") ///
	   style(tex) booktabs nonumbers title("Panel B: With controls")	   

	   clear

*******TABLE 4*******

use "data/Base_ADM_TotalFinal_4Rangos_sim_pen", clear


rename ContVolPrevio ContributedVol
rename TotCotVol cot_vol
rename TotCot cot_obli
rename EverCont Contributed


global OutcomesADM_Resumen ihs_savings NCotVol ihs_cot_vol NCot ihs_cot_obli pensionado

label var ihs_savings     "\shortstack{Total \\ Savings (ihs)}"
label var NCotVol  "\shortstack{N. of \\ Vol. Cont.}"
label var ihs_cot_vol     "\shortstack{Voluntary \\ Savings (ihs)}"
label var NCot     "\shortstack{N. of \\ Mandatory Cont.}"
label var ihs_cot_obli    "\shortstack{Mandatory \\ Savings (ihs)}"
label var pensionado      "Retired"

********************************************************************************

replace ErrorPension = ErrorPension/(res_sim_1+esperada_pens)
replace ErrorPension = 0 if res_sim_1==0 & esperada_pens==0
gen GA = ErrorPension < -0.15 if ErrorPension ~= .
gen GB = -0.15 <= ErrorPension & ErrorPension < 0.15 if ErrorPension ~= .
gen GC = ErrorPension >= 0.15 if ErrorPension ~= .

********************************************************************************

estimates clear

gen Err_1 = Educ1
gen Err_2 = Educ2
gen Err_3 = Educ3
gen Err_4 = Educ4

gen GA_T = Tratamiento*GA
gen GB_T = Tratamiento*GB
gen GC_T = Tratamiento*GC

forvalues t = 2/4 { 

gen Treat_`t' = Tratamiento*Err_`t'

gen GA_Err_`t' = GA*Err_`t'
gen GB_Err_`t' = GB*Err_`t'
gen GC_Err_`t' = GC*Err_`t'

gen T_GA_Err_`t' = Tratamiento*GA*Err_`t'
gen T_GB_Err_`t' = Tratamiento*GB*Err_`t'
gen T_GC_Err_`t' = Tratamiento*GC*Err_`t'
}

foreach var in $OutcomesADM_Resumen {

areg `var' GA_T T_GA_Err_* GB_T T_GB_Err_* GC_T T_GC_Err_* GA GB GC G*_Err_* L2.`var' ${Controles1} if post == 3, a(periodo_exp) robust
est store m14_k1_v`var'
}

label var GA_T "\shortstack{Pers. Info.*Overest.}"        
label var T_GA_Err_2 "\shortstack{Pers. Info.*Overest.* \\ HSD}"         
label var T_GA_Err_3 "\shortstack{Pers. Info.*Overest.* \\ Some college}"
label var T_GA_Err_4 "\shortstack{Pers. Info.*Overest.* \\ University}"  

label var GB_T "\shortstack{Pers. Info.*Correct}"        
label var T_GB_Err_2 "\shortstack{Pers. Info.*Correct* \\ HSD}"         
label var T_GB_Err_3 "\shortstack{Pers. Info.*Correct* \\ Some college}"
label var T_GB_Err_4 "\shortstack{Pers. Info.*Correct* \\ University}" 

label var GC_T "\shortstack{Pers. Info.*Underest.}"
label var T_GC_Err_2 "\shortstack{Pers. Info.*Underest.* \\ HSD}"         
label var T_GC_Err_3 "\shortstack{Pers. Info.*Underest.* \\ Some college}"
label var T_GC_Err_4 "\shortstack{Pers. Info.*Underest.* \\ University}"  

esttab m14_k1_* using tab/table_8_impact_by_mistake_knowledge_education.tex , ///
	   keep(GA_T T_GA_Err_* GB_T T_GB_Err_* GC_T T_GC_Err_*) stats(r2 N ControlMean, fmt(%9.3f %9.0gc %12.3f)) ///
	   cells(b(fmt(%9.3f) star) se(par fmt(%9.3f))) starlevels(* 0.10 ** 0.05 *** 0.01) label replace ///
	   note("Robust standard errors in parentheses. *** p$<$0.01 ** p$<$0.05 * p$<$0.1") ///
	   style(tex) booktabs nonumbers title("Panel A: By estimation mistake and pension system knowledge")

	   clear

use "data/Base_ADM_TotalFinal_4Rangos_sim_pen", clear


rename ContVolPrevio ContributedVol
rename TotCotVol cot_vol
rename TotCot cot_obli
rename EverCont Contributed


global OutcomesADM_Resumen ihs_savings NCotVol ihs_cot_vol NCot ihs_cot_obli pensionado

label var ihs_savings     "\shortstack{Total \\ Savings (ihs)}"
label var NCotVol  "\shortstack{N. of \\ Vol. Cont.}"
label var ihs_cot_vol     "\shortstack{Voluntary \\ Savings (ihs)}"
label var NCot     "\shortstack{N. of \\ Mandatory Cont.}"
label var ihs_cot_obli    "\shortstack{Mandatory \\ Savings (ihs)}"
label var pensionado      "Retired"

********************************************************************************

replace ErrorPension = ErrorPension/(res_sim_1+esperada_pens)
replace ErrorPension = 0 if res_sim_1==0 & esperada_pens==0
gen GA = ErrorPension < -0.15 if ErrorPension ~= .
gen GB = -0.15 <= ErrorPension & ErrorPension < 0.15 if ErrorPension ~= .
gen GC = ErrorPension >= 0.15 if ErrorPension ~= .

********************************************************************************

estimates clear

gen Err_1 = (CalculoPension + PctajeAFP) == 0 if CalculoPension != . & PctajeAFP != . 
gen Err_2 = (CalculoPension + PctajeAFP) == 1 if CalculoPension != . & PctajeAFP != .
gen Err_3 = (CalculoPension + PctajeAFP) == 2 if CalculoPension != . & PctajeAFP != .


gen GA_T = Tratamiento*GA
gen GB_T = Tratamiento*GB
gen GC_T = Tratamiento*GC

forvalues t = 2/3 { 

gen Treat_`t' = Tratamiento*Err_`t'


gen GA_Err_`t' = GA*Err_`t'
gen GB_Err_`t' = GB*Err_`t'
gen GC_Err_`t' = GC*Err_`t'

gen T_GA_Err_`t' = Tratamiento*GA*Err_`t'
gen T_GB_Err_`t' = Tratamiento*GB*Err_`t'
gen T_GC_Err_`t' = Tratamiento*GC*Err_`t'
}

foreach var in $OutcomesADM_Resumen {

areg `var' GA_T T_GA_Err_* GB_T T_GB_Err_* GC_T T_GC_Err_* GA GB GC G*_Err_* L2.`var' ${Controles1} if post == 3, a(periodo_exp) robust
est store m12_k1_v`var'
}


label var GA_T "\shortstack{Pers. Info.*Overest.  }"
label var T_GA_Err_2 "\shortstack{Pers. Info.*Overest.* \\ Medium}"
label var T_GA_Err_3 "\shortstack{Pers. Info.*Overest.* \\ High  }"

label var GB_T "\shortstack{Pers. Info.*Correct}"
label var T_GB_Err_2 "\shortstack{Pers. Info.*Correct* \\ Medium}"
label var T_GB_Err_3 "\shortstack{Pers. Info.*Correct* \\ High  }"

label var GC_T "\shortstack{Pers. Info.*Underest.   }"
label var T_GC_Err_2 "\shortstack{Pers. Info.*Underest.* \\ Medium}"
label var T_GC_Err_3 "\shortstack{Pers. Info.*Underest.* \\ High  }"


esttab m12_k1_* using tab/table_8_impact_by_mistake_knowledge_education.tex , ///
	   keep(GA_T T_GA_Err_* GB_T T_GB_Err_* GC_T T_GC_Err_*) stats(r2 N ControlMean, fmt(%9.3f %9.0gc %12.3f)) ///
	   cells(b(fmt(%9.3f) star) se(par fmt(%9.3f))) starlevels(* 0.10 ** 0.05 *** 0.01) label append ///
	   note("Robust standard errors in parentheses. *** p$<$0.01 ** p$<$0.05 * p$<$0.1") ///
	   style(tex) booktabs nonumbers title("Panel B: By estimation mistake and educational level")


****TABLE A.5*****
	   
use "data/Base_ADM_TotalFinal_4Rangos_sim_pen", clear

gen var1 = NCotVol
gen var2 = ihs_cot_vol
gen var3 = NCot
gen var4 = ihs_cot_obli
gen var5 = pensionado
gen var6 = ihs_savings 

global OutcomesADM_Resumen var1 var2 var3 var4 var5 var6

* grupos de edad
gen grp_1 = (edad <= 34)						if edad~=.
gen grp_2 = (edad >= 35) & (edad <= 49)			if edad~=.
gen grp_3 = (edad >= 50)						if edad~=.
* interactions
forvalues ee = 1/4 {
cap gen Treat`ee' = Tratamiento*grp_`ee'
cap gen T`ee'_post = Treat`ee'*post
cap gen post_`ee' = post*grp_`ee'
cap label var T`ee'_post "$ T_`ee'$"
cap label var Treat`ee' "$ T_`ee'$"
}
********************************************************************************

sort ID1 post
xtset ID1 post
foreach var of varlist $OutcomesADM_Resumen {

	* outcome mean for control group, months 1 to 6 post treatment
	estpost summarize `var' if Tratamiento == 0 & post == 3		// post == 3 means months 1 to 6 post treatment
	if abs(el(e(mean),1,1))>100{
		local mean_`var': di %12.0fc el(e(mean),1,1)
		}
	else{
		local mean_`var': di %12.2fc el(e(mean),1,1)
		}
			
	* regression
	areg `var' Treat* grp_* L2.`var' $Controles1 if post == 3, a(periodo_exp) robust

foreach x in Treat1 Treat2 Treat3 {
	test `x'
	local s_`var'_`x'=cond(r(p)<.01,"***",cond(r(p)<.05,"**",cond(r(p)<.1,"*","")))	 
	if abs(_b[`x'])>100{
		local b_`var'_`x': di %12.0fc _b[`x']
		}
	else{
		local b_`var'_`x': di %12.2fc _b[`x']
		}
	if abs(_se[`x'])>100{
		local se_`var'_`x': di %12.0fc _se[`x']
		}
	else{
		local se_`var'_`x': di %12.2fc _se[`x']
		}
	}
}
	* Number of occurences for each group
	total(grp_1) if grp_1==1 & post==3
	local N_Treat1: di %12.0fc e(N)
	total(grp_2) if grp_2==1 & post==3
	local N_Treat2: di %12.0fc e(N)
	cap total(grp_3) if grp_3==1 & post==3
	cap local N_Treat3: di %12.0fc e(N)


forvalues ee = 1/4 {
cap gen Treat`ee' = .
}

label var Treat1 "Age<=29"
label var Treat2 "30<=Age<=44"
label var Treat3 "Age>=45"


* Generate Table A7
texdoc init tab\het_byage.tex, replace
tex \documentclass[11pt]{article}
tex \input{Preamble.tex}
tex \begin{document}
tex
tex \begin{table}[h!]
tex \caption{"Impact of Personalized Information on behavior within the pension system, by type of message, first 6 months."}
tex \label{tab:tableA7}
tex \begin{center}
	tex \begin{tabular}{p{5cm}cccccccc}
	tex \toprule
	tex 						& Total savings &	\multicolumn{2}{c}{Voluntary savings} 								& \multicolumn{2}{c}{Mandatory savings}  								& \multicolumn{1}{c}{}				&\\
	tex \cline{3-4} \cline{5-6}
	tex First best				&	\multicolumn{1}{c}{num.} 		&	\multicolumn{1}{c}{vol.} 		& \multicolumn{1}{c}{num.}			& \multicolumn{1}{c}{vol.}  		& \multicolumn{1}{c}{Retired}		& \multicolumn{1}{c}{Obs.}		\\
	tex \midrule
	foreach x in Treat1 Treat2 Treat3 {
	tex   `:var label `x'' 		& `b_var6_`x''`s_var6_`x'' & `b_var1_`x''`s_var1_`x''			& `b_var2_`x''`s_var2_`x''			&	`b_var3_`x''`s_var3_`x''		& `b_var4_`x''`s_var4_`x''			& `b_var5_`x''`s_var5_`x''			& `N_`x''		\\
	tex               			& (`se_var6_`x'') & (`se_var1_`x'')       			& (`se_var2_`x'') 					&   (`se_var3_`x'')				& (`se_var4_`x'')					& (`se_var5_`x'')					&\\
	}
	tex \\
	tex Control Mean			&	`mean_var6' & `mean_var1'						&	`mean_var2'						&	`mean_var3'						&	`mean_var4'						&	`mean_var5'						&\\
	tex \bottomrule
	tex \multicolumn{8}{p{15cm}}{\quad \footnotesize Robust standard errors in parentheses. Sample size is N=2,536 for each outcome. Regressions include exposition period fixed effects and controls by gender, educational level, income, simulated pension and whether the person is head of household. *** p<0.01 ** p<0.05 * p<0.1} \\
	tex \end{tabular}
tex \end{center}
tex \end{table}
tex
tex \end{document} 
texdoc close

clear


****TABLE A.6***************

use "data/Base_ADM_TotalFinal_4Rangos_sim_pen", clear

gen var1 = NCotVol
gen var2 = ihs_cot_vol
gen var3 = NCot
gen var4 = ihs_cot_obli
gen var5 = pensionado
gen var6 = ihs_savings 

global OutcomesADM_Resumen var1 var2 var3 var4 var5 var6

* grupos de edad
gen grp_1 = rem_actual<250000 if rem_actual~=.
gen grp_2 = rem_actual>=250000 & rem_actual<500000		if rem_actual~=.
gen grp_3 = rem_actual>=500000 if rem_actual~=.
* interactions
forvalues ee = 1/3 {
cap gen Treat`ee' = Tratamiento*grp_`ee'
cap gen T`ee'_post = Treat`ee'*post
cap gen post_`ee' = post*grp_`ee'
cap label var T`ee'_post "$ T_`ee'$"
cap label var Treat`ee' "$ T_`ee'$"
}
********************************************************************************

sort ID1 post
xtset ID1 post
foreach var of varlist $OutcomesADM_Resumen {

	* outcome mean for control group, months 1 to 6 post treatment
	estpost summarize `var' if Tratamiento == 0 & post == 3		// post == 3 means months 1 to 6 post treatment
	if abs(el(e(mean),1,1))>100{
		local mean_`var': di %12.0fc el(e(mean),1,1)
		}
	else{
		local mean_`var': di %12.2fc el(e(mean),1,1)
		}
			
	* regression
	areg `var' Treat* grp_* L2.`var' $Controles1 if post == 3, a(periodo_exp) robust

foreach x in Treat1 Treat2 Treat3 {
	test `x'
	local s_`var'_`x'=cond(r(p)<.01,"***",cond(r(p)<.05,"**",cond(r(p)<.1,"*","")))	 
	if abs(_b[`x'])>100{
		local b_`var'_`x': di %12.0fc _b[`x']
		}
	else{
		local b_`var'_`x': di %12.2fc _b[`x']
		}
	if abs(_se[`x'])>100{
		local se_`var'_`x': di %12.0fc _se[`x']
		}
	else{
		local se_`var'_`x': di %12.2fc _se[`x']
		}
	}
}
	* Number of occurences for each group
	total(grp_1) if grp_1==1 & post==3
	local N_Treat1: di %12.0fc e(N)
	total(grp_2) if grp_2==1 & post==3
	local N_Treat2: di %12.0fc e(N)
	cap total(grp_3) if grp_3==1 & post==3
	cap local N_Treat3: di %12.0fc e(N)


forvalues ee = 1/4 {
cap gen Treat`ee' = .
}

label var Treat1 "Wage below minimum wage"
label var Treat2 "Wage between one and two minimum wages"
label var Treat3 "Wage higher than two minimum wages"


* Generate Table A7
texdoc init tab\het_bywage.tex, replace
tex \documentclass[11pt]{article}
tex \input{Preamble.tex}
tex \begin{document}
tex
tex \begin{table}[h!]
tex \caption{"Impact of Personalized Information on behavior within the pension system, by type of message, first 6 months."}
tex \label{tab:tableA7}
tex \begin{center}
	tex \begin{tabular}{p{5cm}cccccccc}
	tex \toprule
	tex 						& Total savings &	\multicolumn{2}{c}{Voluntary savings} 								& \multicolumn{2}{c}{Mandatory savings}  								& \multicolumn{1}{c}{}				&\\
	tex \cline{3-4} \cline{5-6}
	tex First best				&	\multicolumn{1}{c}{num.} 		&	\multicolumn{1}{c}{vol.} 		& \multicolumn{1}{c}{num.}			& \multicolumn{1}{c}{vol.}  		& \multicolumn{1}{c}{Retired}		& \multicolumn{1}{c}{Obs.}		\\
	tex \midrule
	foreach x in Treat1 Treat2 Treat3 {
	tex   `:var label `x'' 		& `b_var6_`x''`s_var6_`x'' & `b_var1_`x''`s_var1_`x''			& `b_var2_`x''`s_var2_`x''			&	`b_var3_`x''`s_var3_`x''		& `b_var4_`x''`s_var4_`x''			& `b_var5_`x''`s_var5_`x''			& `N_`x''		\\
	tex               			& (`se_var6_`x'') & (`se_var1_`x'')       			& (`se_var2_`x'') 					&   (`se_var3_`x'')				& (`se_var4_`x'')					& (`se_var5_`x'')					&\\
	}
	tex \\
	tex Control Mean			&	`mean_var6' & `mean_var1'						&	`mean_var2'						&	`mean_var3'						&	`mean_var4'						&	`mean_var5'						&\\
	tex \bottomrule
	tex \multicolumn{8}{p{15cm}}{\quad \footnotesize Robust standard errors in parentheses. Sample size is N=2,536 for each outcome. Regressions include exposition period fixed effects and controls by gender, educational level, income, simulated pension and whether the person is head of household. *** p<0.01 ** p<0.05 * p<0.1} \\
	tex \end{tabular}
tex \end{center}
tex \end{table}
tex
tex \end{document} 
texdoc close
